﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using ATSBLL;
using CrystalDecisions.CrystalReports.Engine;
using ATSModel;

public partial class TestDataReport_PIMReport_PIMDataReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("PIMReport.rpt"));
        if (this.TextBox1.Value == "" || this.TextBox2.Value == "")
        {
            //this.Button1.Attributes.Add("onclick", "return confirm('请选择起始与截止日期！');");
            //this.Button1.Attributes.Add("onclick", "<script>alert(123);</script>");
            //Response.Write("<script>alert('删除成功!')</script>");
            ScriptManager.RegisterStartupScript(this.UpdatePanel1,
                        this.GetType(), "click", "<script>alert('" + "请先选择起始与终止日期！" + "');</script>", false);

            //ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + "123" + "');</script>");
            return;
        }
        IList<PIMReportInfo> list = GetDataByDate();

        this.CrystalReportSource1.ReportDocument.SetDataSource(list);
        this.CrystalReportSource1.DataBind();
        this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
        this.CrystalReportViewer1.DataBind();
        this.CrystalReportViewer1.Visible = true;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("PIMReport.rpt"));
        IList<PIMReportInfo> list = GetAllData();

        this.CrystalReportSource1.ReportDocument.SetDataSource(list);
        this.CrystalReportSource1.DataBind();
        this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
        this.CrystalReportViewer1.DataBind();
        this.CrystalReportViewer1.Visible = true;
    }

    protected IList<PIMReportInfo> GetDataByDate()
    {
        DateTime dt1 = DateTime.Parse(this.TextBox1.Value.Trim());
        DateTime dt2 = DateTime.Parse(this.TextBox2.Value.Trim());

        IList<PIMReportInfo> testItems = new List<PIMReportInfo>();
        Report_PIMData elect = new Report_PIMData();
        testItems = elect.GetPIMDataByDate(dt1, dt2);
        return testItems;
    }

    protected IList<PIMReportInfo> GetAllData()
    {
        IList<PIMReportInfo> testItems = new List<PIMReportInfo>();
        Report_PIMData elect = new Report_PIMData();

        testItems = elect.GetPIMData();
        return testItems;
    }
}
